﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using System.Text;
using System.Data;


namespace TaoBaoProject.Handlers.QQRelateHandler
{
  /// <summary>
  /// Summary description for GetQQRelateHandler
  /// </summary>
  public class GetQQRelateHandler : IHttpHandler
  {
    QQRelationBLL qqrelateBll = new QQRelationBLL();
    public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "text/plain";
      try
      {
        StringBuilder sbRet = new StringBuilder();
        DataTable dt;

        string txtQQ = context.Request["txtQQ"];
        if (txtQQ != null && txtQQ.Trim() != "")
        {
          dt = qqrelateBll.getSameQQ(txtQQ);
          sbRet.Append(Common.Utility.GetJsonString(dt));
          context.Response.Write(sbRet);
        }
        else
        {
          string page = context.Request["page"];
          string rows = context.Request["rows"];
          string sort = context.Request["sort"];
          string order = context.Request["order"];

          DataView dv = null;
          dt = qqrelateBll.GetAllRelations();
          dv = dt.DefaultView;
          dv.Sort = sort + " " + order;

          dt = dv.ToTable();
          dt.Columns.Add("id");
          for (int i = 0; i < dt.Rows.Count; i++)
          {
            dt.Rows[i]["id"] = dt.Rows[i]["QQMappID"];
          }
          sbRet.Append(Common.Utility.GetJsonString(dt));

          context.Response.Write(sbRet);
        }
      }
      catch (Exception ex)
      {

      }


    }
    private void HandlerSearch()
    {

    }

    public bool IsReusable
    {
      get
      {
        return false;
      }
    }
  }
}